package com.hpin.fansea.home;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hpin.fansea.R;
import com.hpin.fansea.base.BaseActivity;
import com.hpin.fansea.utils.CommonUtils;
import com.hpin.fansea.utils.Constant;

/**
 * 缴费页面
 * Created by Aaron on 15/9/14.
 */
public class PaymentActivity extends BaseActivity {

    private ImageView iv_personal;
    private ImageView iv_unit;
    private TextView tv_pay_community;
    private TextView tv_roomnum;
    private EditText et_contact;
    private EditText et_contact_tel;
    private EditText et_unit_name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_property_fee);

        initWidget();

        setUserData();

    }

    private void initWidget() {

        ImageView iv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);

        tv_title.setText(getResources().getString(R.string.pay));

        iv_left.setOnClickListener(this);


        tv_pay_community = (TextView) findViewById(R.id.tv_pay_community);
        tv_roomnum = (TextView) findViewById(R.id.tv_roomnum);

        et_contact = (EditText) findViewById(R.id.et_contact);
        et_contact_tel = (EditText) findViewById(R.id.et_contact_tel);

        iv_personal = (ImageView) findViewById(R.id.iv_personal);
        iv_unit = (ImageView) findViewById(R.id.iv_unit);

        et_unit_name = (EditText) findViewById(R.id.et_unit_name);
        Button btn_next = (Button) findViewById(R.id.btn_next);

        iv_personal.setOnClickListener(this);
        iv_unit.setOnClickListener(this);

        btn_next.setOnClickListener(this);

    }

    /**
     * 设置用户数据
     */
    private void setUserData() {

        tv_pay_community.setText(sp.getString(Constant.communityName, ""));//小区
        tv_roomnum.setText(sp.getString(Constant.projectName, "") + sp.getString(Constant.buildingNo, "")
                + sp.getString(Constant.unitNo, "") + sp.getString(Constant.houseNo, ""));//房号
        et_contact.setText(sp.getString(Constant.userName, ""));
        et_contact_tel.setText(sp.getString(Constant.mobile, ""));

    }

    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {

            case R.id.iv_left:

                finish();

                break;

            case R.id.iv_personal://个人发票

                iv_personal.setSelected(true);
                iv_unit.setSelected(false);

                break;
            case R.id.iv_unit://单位发票

                iv_unit.setSelected(true);
                iv_personal.setSelected(false);

                break;
            case R.id.btn_next://下一步

                nextStep();

                break;

        }

    }

    /**
     * 下一步
     */
    private void nextStep() {

        //发票类型
        if (iv_unit.isSelected()) {

            if (CommonUtils.isNull(et_unit_name.getText().toString().trim())) {
                showToast("请输入单位名称");
                return;
            }

        }else if (iv_personal.isSelected()) {

        }else {

        }

        Intent mIntent = new Intent(this, PaymentDetailActivity.class);

        mIntent.putExtra("contact", et_contact.getText().toString().trim());
        mIntent.putExtra("phone", et_contact_tel.getText().toString().trim());
        mIntent.putExtra("unitName", et_unit_name.getText().toString().trim());

        startActivity(mIntent);


    }
}
